package vip.xiaonuo.app.core.listener;

import cn.hutool.log.Log;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import vip.xiaonuo.app.core.consts.AppRedisConstant;
import vip.xiaonuo.app.modular.dict.DictResult;
import vip.xiaonuo.app.modular.dict.area.entity.AppDictArea;
import vip.xiaonuo.app.modular.dict.area.service.AppDictAreaService;
import vip.xiaonuo.app.modular.dict.career.entity.AppDictCareer;
import vip.xiaonuo.app.modular.dict.career.service.AppDictCareerService;
import vip.xiaonuo.app.modular.dict.educ.entity.AppDictEduc;
import vip.xiaonuo.app.modular.dict.educ.service.AppDictEducService;
import vip.xiaonuo.app.modular.dict.height.entity.AppDictHeight;
import vip.xiaonuo.app.modular.dict.height.service.AppDictHeightService;
import vip.xiaonuo.app.modular.dict.income.entity.AppDictIncome;
import vip.xiaonuo.app.modular.dict.income.service.AppDictIncomeService;
import vip.xiaonuo.app.modular.dict.tag.result.DictTagResult;
import vip.xiaonuo.app.modular.dict.tag.service.AppDictTagService;
import vip.xiaonuo.app.modular.dict.weight.entity.AppDictWeight;
import vip.xiaonuo.app.modular.dict.weight.service.AppDictWeightService;
import vip.xiaonuo.core.pojo.node.NodeVo;
import vip.xiaonuo.sys.core.cache.RedisCache;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>Title : 字典监听器</p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows11</p>
 *
 * @Author : zxw
 * @Date 2023/9/25 11:01
 */
@Component
public class DictInitListener implements CommandLineRunner {


    private static final Log log = Log.get();

    @Resource
    private RedisCache redisCache;
    @Resource
    private AppDictCareerService appDictCareerService;
    @Resource
    private AppDictAreaService appDictAreaService;
    @Resource
    private AppDictWeightService appDictWeightService;
    @Resource
    private AppDictHeightService appDictHeightService;
    @Resource
    private AppDictEducService appDictEducService;
    @Resource
    private AppDictIncomeService appDictIncomeService;
    @Resource
    private AppDictTagService appDictTagService;


    @Override
    public void run(String... args) {
        DictResult dictResult = new DictResult();
        //职业
        List<AppDictCareer> dictCareerList = appDictCareerService.getDictCareerList();
        List<NodeVo> dictCareerNodeVos = appDictCareerService.buildDictCareers(dictCareerList, 0);
        //标签
        DictTagResult dictTagResultList = appDictTagService.getDictTagResultList();
        //省市区
        List<AppDictArea> dictAreaList = appDictAreaService.getDictAreaList();
        List<NodeVo> dictAreaNodeVos = appDictAreaService.buildDictChinaAreas(dictAreaList, 0);
        //身高
        List<AppDictHeight> dictHeightList = appDictHeightService.appList();
        //体重
        List<AppDictWeight> dictWeightList = appDictWeightService.appList();
        //学历
        List<AppDictEduc> dictEducList = appDictEducService.appList();
        //收入
        List<AppDictIncome> dictIncomeList = appDictIncomeService.appList();

        //缓存redis

        dictResult.setDictCareerNodeVos(dictCareerNodeVos);
        dictResult.setDictTagResult(dictTagResultList);
        dictResult.setDictAreaNodes(dictAreaNodeVos);
        dictResult.setDictHeights(dictHeightList);
        dictResult.setDictWeights(dictWeightList);
        dictResult.setDictEducs(dictEducList);
        dictResult.setDictIncomes(dictIncomeList);

        redisCache.setCache(AppRedisConstant.APP_DICT, dictResult);

//        log.info(">>> 缓存字典集合完成!参数：{}", dictResult);

    }
}
